<?php


if (!defined("EXPONENT")) exit("");
$gallery_col_id=3;
$gallery = null;
if (isset($_POST['gid'])) {
	$gallery = $db->selectObject("imagegallery_gallery","id=".$_POST['gid']);
	if ($gallery) {
		$loc = unserialize($gallery->location_data);
	}
}

if ($gallery) {

	if (exponent_permissions_check('manage',$loc)) {
		$image = null;
		$image->gallery_id = $_POST['gid'];
		$image->newwindow = 1;
		
		$firstrank = $db->max('imagegallery_image','rank','gallery_id','gallery_id='.$gallery->id);
		if ($firstrank == null) $firstrank = -1; // It will be incremented
		
		$success = true;
		for ($i = 0; $i < $_POST['count']; $i++) 
      if (isset($_POST["file{$i}"]) && ($_POST["file{$i}"] > -1 )){
			$firstrank++;
			$image->rank = $firstrank;
			$image->name = $_POST["name$i"];
			$image->alt = $_POST["alt$i"];
			$image->file_id = intval($_POST["file{$i}"]);
				
				//$thumbname = imagegallerymodule::createThumbnailFile($file, $gallery->box_size); 
				//$image->thumbnail = $thumbname; 
				//$popname = imagegallerymodule::createEnlargedFile($file, $gallery->pop_size); 
				//$image->enlarged = $popname; 
				
				$db->insertObject($image,"imagegallery_image");
			}
		
		if ($success) {
			exponent_flow_redirect();
		}
	} else {
		echo SITE_403_HTML;
	}
} else {
	echo SITE_404_HTML;
}

?>
